package com.softcits.upload.demo;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLEncoder;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;

@WebServlet(urlPatterns="/download")
public class FileDownloadServlet extends HttpServlet {

    
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        resp.setHeader("content-disposition","inline;filename="+URLEncoder.encode("日语语法大全整理笔记.pdf","UTF-8"));
        
        ///resp.setContentType("application/octet-stream");
        
        resp.setContentType("application/pdf");
        
       // resp.setContentType("text/plain");
        File file = new File("./files/日语语法大全整理笔记.pdf");
        FileInputStream fis = new FileInputStream(file);
        OutputStream os = resp.getOutputStream();
        IOUtils.copy(fis, os);
        
        IOUtils.closeQuietly(fis);
        os.flush();
        os.close();
        
        
        
    }
}
